<%-- 
    Document   : ticketdetails
    Created on : Nov 29, 2009, 10:53:26 PM
    Author     : brian
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.ArrayList,helpdesk.HelpTicket,helpdesk.HelpTicketUpdate,helpdesk.LoginCheck"%>

<%! // declarations go in this kind of tag
    String error;
    HelpTicket helpTicket;
    ArrayList<HelpTicketUpdate> helpTicketUpdates;
 %>

 <% // embedded java code goes in this kind of tag
    error = (String)request.getAttribute("error");
    if (error == null)
        error = "";

    helpTicket = (HelpTicket)request.getAttribute("helpTicket");
    helpTicketUpdates = (ArrayList<HelpTicketUpdate>)request.getAttribute("helpTicketUpdates");
 %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <%@include file="headtags.html"%>
        <title>Help ticket details</title>
    </head>
    <body>
        <%@include file="menu.html"%>

        <%-- The tag below places the output of the java expression on the page --%>
        <%= error %>
        <table class="content" width ="100%"><tr class="heading"><td align="center">Ticket Details</td></tr><tr><td>
        <table class="ticket">
            <tr>
                <th class="ticket">ID</th>
                <th class="ticket">Created by</th>
                <th class="ticket">Area</th>
                <th class="ticket">Priority</th>
                <th class="ticket">Title</th>
                <th class="ticket">Description</th>
                <th class="ticket">Assigned to</th>
                <th class="ticket">Created on</th>
                <th class="ticket">Last Updated</th>
                <th class="ticket">Status</th>
            </tr>
            <tr>
                <%
                if (helpTicket != null)
                {
                %>
                <td class="ticket"><%= helpTicket.getId() %></a></td>
                <td class="ticket"><a href="viewprofile.jsp?userid=<%= helpTicket.getUserId() %>"><%= helpTicket.getUser() %></a>
                    <%= "" + (LoginCheck.isLoggedIn(helpTicket.getUserId())?" (online)":"") %></td>
                <td class="ticket"><%= helpTicket.getExpertise() %></td>
                <td class="ticket"><%= helpTicket.getPriority() %></td>
                <td class="ticket"><%= helpTicket.getTitle() %></td>
                <td class="ticket"><%= helpTicket.getDescription() %></td>
                <td class="ticket"><%= helpTicket.getSupportUser() != null
                    ? "<a href=\"viewprofile.jsp?userid=" + helpTicket.getSupportUserId() + "\">" + helpTicket.getSupportUser() + "</a>"
                    : "Unassigned" %></td>
                <td class="ticket"><%= helpTicket.getDateOpened() %></td>
                <td class="ticket"><%= helpTicket.getModified() %></td>
                <td class="ticket"><%= helpTicket.getDateClosed() != null ? "Closed on " + helpTicket.getDateClosed() : "Open" %></td>
                <%
                }
                %>
            </tr>
        </table>
          <%    if (helpTicketUpdates != null && helpTicketUpdates.size() != 0)
                {
              %>
        <p>Updates:</p>
        <table class="ticket">            
            <tr>
                <th class="ticket">Timestamp</th>
                <th class="ticket">Author</th>
                <th class="ticket">Message</th>
            </tr>
            <%
                for (int i=0;i<helpTicketUpdates.size();i++)
                    {
                        HelpTicketUpdate t = helpTicketUpdates.get(i);
                        %>
                        <tr>
                            <td class="ticket"><%= t.getDate() %></td>
                            <td class="ticket"><a href="viewprofile.jsp?userid=<%= t.getUserId() %>"><%= t.getUserName() %></a>
                                <%= "" + (LoginCheck.isLoggedIn(t.getUserId())?" (online)" : "") %></td>
                            <td class="ticket"><%= t.getContents() %></td>
                        </tr>
                        <%
                    }
                    %> </table> <%
                } else
                    {
                        %><p>There are currently no updates for this ticket.</p><%
                    }
            
            if (helpTicket != null)
            {
                %>
                <form name="update_form" method="post" action="updateticket.jsp">
                    <input type="hidden" name="ticketId" id="ticketId" value="<%= helpTicket.getId() %>" />
                    <table>
                        <tr>
                            <td><textarea  name="contents" id="contents" rows="10" cols="75"></textarea><td>
                        </tr>
                        <tr>
                            <td>
                                <input type="submit" value="Submit Update"/>
                                &nbsp;&nbsp;&nbsp;&nbsp;
                                Close Ticket<input type="checkbox" name="closed" value="Close Ticket"/>
                            </td>
                        </tr>                        
                    </table>
                </form>
                <%
            }
            %>
            </td></tr></table>
    </body>
</html>
